var pageIndex = 0;
var pageSize = 5;
var pageTotal = 1;
$(document).ready(function () {
    search();
});
function resetPage() {
    pageIndex = 0;
}
function search() {
    $.get(
        "/record/search?carId=" + $("#carId").val() + "&page=" + pageIndex + "&pageSize=" + pageSize,
        function (data, status) {
            pageTotal = data[data.length-1] - 1;
            if (pageTotal < 0) pageTotal = 0;
            $("#parking tbody").empty();
            for (var i=0;i<data.length-1;i++) {
                $("#parking tbody").append(insertTableRow(data[i]));
            }
            $("#showpage").html("第" + (pageIndex + 1) + " 页，共 " + (pageTotal + 1) + " 页");
        }
    );
}
function miss(e) {
    switch (e.innerHTML) {
        case "首页":
            pageIndex = 0;
            search();
            break;
        case "上一页":
            if (pageIndex > 0) {
                pageIndex--;
                search();
            }
            break;
        case "下一页":
            if (pageIndex < pageTotal) {
                pageIndex++;
                search();
            }
            break;
        case "尾页":
            pageIndex = pageTotal;
            search();
            break;
    }
}
function insertTableRow(data) {
    return "<tr>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.parkId + "</td>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.parkCarId + "</td>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.parkEnterTime + "</td>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.parkOutTime + "</td>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.parkPrice + "</td>\n" +
        "<td style='display: table-cell; vertical-align: middle;'>" + data.consumePayAmount + "</td>\n" +
        "<td style='display:table-cell; vertical-align:middle'><span class='label " + (data.parkStatus === 1 ? "label-success" : "label-danger") + "'>" + (data.parkStatus === 1 ? "完成" : "未完成") + "</span></td>\n" +
        "</tr>";
}